<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <div class="box">
        <h2 class="txt">请点击按钮开始抽奖</h2>
        <input type="button" value="开始" id="start">
        <input type="button" value="停止" id="stop" disabled>
    </div>
</body>
<script src="../public.js"></script>
<script>

    var oTxt = document.querySelector(".txt")
    var oStart = document.querySelector("#start")
    var oStop = document.querySelector("#stop")

    var arr = ["特等奖","一等奖","二等奖","三等奖","参与奖","谢谢惠顾"];

    // 每种奖项的几率相等
    // 0 ~ length-1

    // 从大到小，几率递增
    // 0 ~ 1
    // 0~0.01特等奖
    // 0.01~0.1一等奖
    // 0.1~0.2二等奖
    // 0.2~0.35三等奖
    // 0.35~0.55参与奖
    // 0.55~1谢谢
    // Math.random() > 0 && Math.random() < 0.01

    var t = null;
    oStart.onclick = function(){
        // 切换开始和停止按钮的可用状态
        this.disabled = true;
        oStop.disabled = false;
        // 开启计时器，快速轮换奖项
        t = setInterval(function(){
            oTxt.innerText = arr[random(0, arr.length-1)]
            oTxt.style.background = randomColor();
        }, 50);
    }
    
    oStop.onclick = function(){
        // 切换开始和停止按钮的可用状态
        this.disabled = true;
        oStart.disabled = false;
        // 清除计时器，确定奖项
        clearInterval( t );
    }

</script>
</html>